﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.Utils;
using Ccit.OA.MsNotify;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Ccit.OA.Notify
{
    public partial class notify_manage_edit : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                _hidsRecId.Value = (null != Request.QueryString["NotifyId"]) ? Request.QueryString["NotifyId"].ToString() : "";
                InitPage();
                InitBinde();    
            } 
        }

        private void InitBinde()
        {
            if (_hidsRecId.Value != "")
            {
                NotifyBLL Bll = new NotifyBLL();
                MsNotifyMessage ms = Bll.GetNotiFyMessage(_hidsRecId.Value);
                if(ms!=null)
                {
                    txtName.Text = (ms.title!="")?ms.title:"";
                    ddlType.SelectedValue = (ms.type != "") ? ms.type : "";
                    ddlDeptId.SelectedValue = (ms.deptid != "") ? ms.deptid : "";
                    ddlImportance.SelectedValue = (ms.importance != "") ? ms.importance : "";
                    _hidRangeMarkId.Value = ms.rangemark;
                    _hidRange.Value = ms.range;
                    txtRange.Text = SysInterface.GetNameStrByIdStr(ms.range, ms.rangemark, ",");
                    freText.Text = ms.content;
                    if(ms.receipt=="1")
                    {
                        chkOpinion.Checked = true;
                        txtRcontent.Text = ms.receiptcontent;
                        txtRcontent.Enabled = true;
                    }
                    ucAttach.EditShow("0020", ms.id);
                }
            }
        }
        private void InitPage()
        {
            CtrInterface.BindDropDown(ref ddlImportance, "bas_a1", "bas_a1_30", "bas_a1_40", false, "", "bas_a1_20='995'");
            CtrInterface.BindDropDown(ref ddlDeptId, "v_dept", "DEPTID", "DEPTNAME", false, "", "");
            NotifyBLL Bll = new NotifyBLL();
            Bll.DoAddDownList(ref ddlType);
            Bll = null;
        }
        /// <summary>
        /// save dep address info
        /// </summary>
        /// <param name="jsonExpr"></param>
        /// <param name="ctrlType"></param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static string DoSave(string jsonExpr,string type)
        {
            MsNotifyMessage ms = (MsNotifyMessage)JavaScriptConvert.DeserializeObject(jsonExpr, typeof(MsNotifyMessage)); 
            NotifyBLL BLL = new NotifyBLL();
            List<string> lstResult = BLL.DoSaveNotiFyMessage(ms);
            var newObj = new { resultSign = lstResult[0], message = lstResult[1], resulttype=type };
            string serExpr = JavaScriptConvert.SerializeObject(newObj); 
            ms = null;
            BLL = null;
            return serExpr;
        }
        /// <summary>
        /// 获取通知内容信息
        /// </summary>
        /// <param name="NotifyId"></param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static string GetContent(string NotifyId)
        {             
            NotifyBLL BLL = new NotifyBLL();
            string scontent = BLL.GetNotyfyContent(NotifyId);
            BLL = null;
            return scontent;
        }
        protected void lnbQuery_Click(object sender, EventArgs e)
        {
            bool bSave = false;
            bSave = ucAttach.SaveAttaches("0020", _hidsRecId.Value);  //存附件              
        } 
    }
}
